#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 3e5 + 10;

ll n, k;
priority_queue <pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>q;


void solve()
{
    cin >> n >> k;
    ll t = 0;
    for (ll i = 1;i <= n;i++) {
        ll a, b, c;cin >> a >> b >> c;
        t = max(t, a);
        while (!q.empty() && q.top().first <= t) {
            k += q.top().second;q.pop();
        }

        while (!q.empty() && c > k) {
            auto [x, y] = q.top();q.pop();
            k += y;
            t = max(t, x);
            while (!q.empty() && q.top().first <= t) {
                k += q.top().second;q.pop();
            }
        }

        k -= c;
        q.push({ t + b,c });
        cout << t << '\n';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}